package cn.newtest.common.dbutils;

import org.apache.commons.configuration.PropertiesConfiguration;


/**
 * 
 * @author wangchui(baiyibing@gmail.com)
 * @version 1.0 TODO
 * 
 */
public class DBUtilsFactory {
	private DBUtils aDBUtils = null;

	private static DBUtilsFactory aDBUtilsFactory = null;

	private DBUtilsFactory() {
	}

	public static synchronized DBUtilsFactory getInstance() {
		try {
			if (aDBUtilsFactory == null) {
				aDBUtilsFactory = new DBUtilsFactory();
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return aDBUtilsFactory;
	}

	public DBUtils getDBUtils() {
		if (aDBUtils == null) {
			try {
				PropertiesConfiguration config = new PropertiesConfiguration(
						"db.properties");
				String className = (String) config.getProperty("DBUtilsName");
				aDBUtils = (DBUtils) Class.forName(className).newInstance();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return this.aDBUtils;
	}
}